package com.designPattern.ProxyPattern;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2018/3/12.
 */

public class DynamicProxy implements InvocationHandler {

    private Object obj;

    public DynamicProxy(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        //这里可以对方法名进行判断过滤 if(method.getName().equals("***"))
        switch (method.getName()) {
            case "chooseRestaurant":
            case "orderLunch":
            case "packLunch":
                System.out.print("同事帮忙");
                break;
        }
        Object result = method.invoke(obj, objects);//调用方法
        return result;
    }
}
